package orthoplanner.com.google.code.eventhandlers;

import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;

import orthoplanner.com.google.code.tools.Drawable;
import orthoplanner.com.google.code.ui.AdvanceDrawablePanel;
import orthoplanner.com.google.code.ui.ImageViewer;

public class AdvanceHandler extends MouseAdapter {
	ImageViewer imgViewer;
	JFrame frame;
	GridBagConstraints gbc;
	public AdvanceHandler(ImageViewer imgViewer) {
		this.imgViewer=imgViewer;
	
	}
	@Override
	public void mousePressed(MouseEvent e) {
		if(frame!=null) frame.dispose();
		
		frame=new JFrame("Advance controls");		
		gbc=new GridBagConstraints();
	
		DrawableDeleteHandler ddh=new DrawableDeleteHandler(imgViewer.getDrawables(),frame);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		//frame.removeAll();
		gbc.gridheight=1;
		gbc.gridwidth=1;
		gbc.insets=new Insets(1, 2, 2, 2);
		gbc.gridx=0;
		gbc.gridy=0;
		gbc.ipadx=2;
		gbc.ipady=3;
		frame.getContentPane().setLayout(new GridBagLayout());
		for(Drawable drawable:imgViewer.getDrawables()){
			frame.add(new AdvanceDrawablePanel(drawable,ddh),gbc);
			System.out.println(">>"+drawable);
			gbc.gridy++;

		}
		
		
		Point cp=GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
		frame.setLocation(cp.x-frame.getWidth(),cp.y-frame.getHeight());
		frame.setVisible(true);
		frame.pack();
	}
	

	
}
